﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using G.Reader.Data;
//using G.Reader.UserInfoService;
//using G.Reader.PushService;

namespace G.Reader
{
    public class GloabalData : NotifyObject
    {
        public const string BingAPPID = "6C85FE2D4B893E982A5D838EE67E4DD41DD48309";
        private static GloabalData instance;
        public static GloabalData Instance
        {
            get
            {
                return instance;
            }
        }

        public GloabalData()
        {
            if (instance != null)
                throw new Exception("只能有一个实例");//之所以这么做，是因为需要配合绑定
            instance = this;
        }
        public Microsoft.Live.LiveConnectSession Session { get; set; }

        #region Settings
        private const string SettingsString = "G.Reader_settings";
        private Settings settings;
        public Settings Settings
        {
            get
            {
                if (settings != null)
                    return settings;
                if (System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Contains(SettingsString))
                {
                    settings = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[SettingsString] as Settings;
                }
                if (settings == null)
                {
                    Settings = new Settings();
                }
                return settings;
            }
            private set
            {
                if (settings != value)
                {
                    settings = value;
                    System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[SettingsString] = settings;
                    System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Save();
                    NotifyPropertyChanged("Settings");
                }
            }
        }
        #endregion


        #region userinfo
        //private const string UserString = "G.Reader_UserInfo";
        //private UserInfo user;
        //public UserInfo User
        //{
        //    get
        //    {
        //        if (user != null)
        //            return user;
        //        if (System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Contains(UserString))
        //        {
        //            user = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[UserString] as UserInfo;
        //        }
        //        return user;
        //    }
        //    set
        //    {
        //        if (user != value)
        //        {
        //            user = value;
        //            System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[UserString] = user;
        //            System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Save();
        //            NotifyPropertyChanged("User");
        //        }
        //    }
        //}
        #endregion


        #region pushInfo
        //private const string PushInfoString = "G.Reader_PushInfo";
        //private PushInfo pushInfo;
        //public PushInfo PushInfo
        //{
        //    get
        //    {
        //        if (pushInfo != null)
        //            return pushInfo;
        //        if (System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Contains(PushInfoString))
        //        {
        //            pushInfo = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[PushInfoString] as PushInfo;
        //        }
        //        return pushInfo;
        //    }
        //    set
        //    {
        //        if (pushInfo != value)
        //        {
        //            pushInfo = value;
        //            System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[PushInfoString] = pushInfo;
        //            System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Save();
        //            NotifyPropertyChanged("PushInfo");
        //        }
        //    }
        //}
        #endregion


        private BookDataBase bookDataBase;
        public BookDataBase BookDataBase
        {
            get
            {
                if (bookDataBase == null)
                    bookDataBase = BookDataBase.Create();
                return bookDataBase;
            }
        }



    }
}
